package com.echo.im.client.config;

import com.echo.im.client.handler.PushMessageHandler;
import com.echo.im.client.handler.RecvOfflineHandler;
import com.echo.im.client.handler.RouteSuccessHandler;
import com.echo.im.client.router.support.BaseMessageRouter;
import com.echo.im.client.router.support.PlatformMessageRouter;
import com.echo.im.client.status.UserStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: echo
 * @time: 2024-08-26
 */
@Configuration
@ConditionalOnProperty(name = "im.client.message-route-enabled", havingValue = "true", matchIfMissing = false)  // 通过配置控制装配
public class MessageRouteConfig {

    @Bean
    public PlatformMessageRouter platformMessageRouter(UserStatusService userStatusService, PushMessageHandler pushMessageHandler) {
        return new PlatformMessageRouter(userStatusService,pushMessageHandler);
    }

    @Bean
    public BaseMessageRouter baseMessageRouter(UserStatusService userStatusService,
                                               @Autowired(required = false) RecvOfflineHandler recvOfflineHandler,
                                               @Autowired(required = false) RouteSuccessHandler routeSuccessHandler,
                                               PushMessageHandler pushMessageHandler) {
        return new BaseMessageRouter(userStatusService, recvOfflineHandler, routeSuccessHandler, pushMessageHandler);
    }

}
